<?php
session_start();
require_once '../includes/config.php';
require_once '../includes/database.php';
require_once '../includes/auth.php';

// 检查权限
$auth = getAuth();
$auth->requireLogin();

// 获取当前用户信息
$currentUser = $auth->getCurrentUser();

// 处理表单提交
$message = '';
if ($_POST) {
    // 这里可以添加修改个人信息的逻辑
    $message = '个人信息更新功能开发中...';
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人信息 - 考勤管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .sidebar {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            min-height: 100vh;
            position: fixed;
            width: 250px;
        }
        .sidebar .nav-link {
            color: white;
            padding: 0.75rem 1rem;
            border-radius: 0.375rem;
            margin: 0.125rem 0.5rem;
        }
        .sidebar .nav-link:hover, .sidebar .nav-link.active {
            background: rgba(255,255,255,0.1);
        }
        .sidebar .nav-link i {
            width: 20px;
            text-align: center;
            margin-right: 0.5rem;
        }
        .main-content {
            margin-left: 250px;
            padding: 20px;
        }
        .navbar-custom {
            background: white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <!-- 侧边栏 -->
    <div class="sidebar">
        <div class="p-3 text-center border-bottom">
            <h4 class="mb-0">
                <i class="fas fa-clock me-2"></i>
                考勤系统
            </h4>
            <small>用户面板</small>
        </div>
        
        <nav class="nav flex-column p-2">
            <a href="dashboard.php" class="nav-link">
                <i class="fas fa-tachometer-alt"></i>
                仪表板
            </a>
            <a href="attendance.php" class="nav-link">
                <i class="fas fa-clipboard-list"></i>
                我的考勤
            </a>
            <a href="profile.php" class="nav-link active">
                <i class="fas fa-user"></i>
                个人信息
            </a>
            <div class="mt-auto p-2">
                <a href="../public/logout.php" class="nav-link text-warning">
                    <i class="fas fa-sign-out-alt"></i>
                    退出登录
                </a>
            </div>
        </nav>
    </div>

    <!-- 主内容区 -->
    <div class="main-content">
        <!-- 顶部导航 -->
        <nav class="navbar navbar-expand navbar-custom mb-4">
            <div class="container-fluid">
                <div class="navbar-nav me-auto">
                    <span class="navbar-text">
                        <i class="fas fa-user me-2"></i>个人信息
                    </span>
                </div>
                <div class="navbar-nav">
                    <span class="navbar-text me-3">
                        <i class="fas fa-user me-2"></i>
                        <?php echo htmlspecialchars($currentUser['full_name']); ?>
                    </span>
                    <a href="dashboard.php" class="nav-link">
                        <i class="fas fa-home"></i> 返回首页
                    </a>
                </div>
            </div>
        </nav>

        <?php if ($message): ?>
            <div class="alert alert-info">
                <i class="fas fa-info-circle me-2"></i>
                <?php echo $message; ?>
            </div>
        <?php endif; ?>

        <div class="row">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-user-edit me-2"></i>基本信息
                        </h5>
                    </div>
                    <div class="card-body">
                        <form method="post">
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label class="form-label">用户名</label>
                                    <input type="text" class="form-control" value="<?php echo htmlspecialchars($currentUser['username']); ?>" readonly>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">角色</label>
                                    <input type="text" class="form-control" value="<?php echo htmlspecialchars($currentUser['role']); ?>" readonly>
                                </div>
                            </div>
                            
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label class="form-label">姓名</label>
                                    <input type="text" class="form-control" value="<?php echo htmlspecialchars($currentUser['full_name']); ?>" readonly>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">邮箱</label>
                                    <input type="email" class="form-control" value="<?php echo htmlspecialchars($currentUser['email']); ?>" readonly>
                                </div>
                            </div>
                            
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label class="form-label">部门</label>
                                    <input type="text" class="form-control" value="<?php echo htmlspecialchars($currentUser['department']); ?>" readonly>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">职位</label>
                                    <input type="text" class="form-control" value="<?php echo htmlspecialchars($currentUser['position']); ?>" readonly>
                                </div>
                            </div>
                            
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label class="form-label">手机号</label>
                                    <input type="text" class="form-control" value="<?php echo htmlspecialchars($currentUser['phone']); ?>" readonly>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label">最后登录</label>
                                    <input type="text" class="form-control" value="<?php echo $currentUser['last_login'] ?: '从未登录'; ?>" readonly>
                                </div>
                            </div>
                            
                            <div class="alert alert-warning">
                                <i class="fas fa-exclamation-triangle me-2"></i>
                                个人信息修改功能开发中，请联系管理员修改。
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            
            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-shield-alt me-2"></i>安全设置
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="d-grid gap-2">
                            <button class="btn btn-outline-primary" disabled>
                                <i class="fas fa-key me-2"></i>修改密码
                            </button>
                            <button class="btn btn-outline-warning" disabled>
                                <i class="fas fa-bell me-2"></i>通知设置
                            </button>
                            <button class="btn btn-outline-info" disabled>
                                <i class="fas fa-language me-2"></i>语言设置
                            </button>
                        </div>
                        <div class="alert alert-info mt-3">
                            <small>
                                <i class="fas fa-info-circle me-2"></i>
                                安全设置功能正在开发中...
                            </small>
                        </div>
                    </div>
                </div>
                
                <div class="card mt-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-chart-bar me-2"></i>统计信息
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="text-center">
                            <div class="mb-3">
                                <i class="fas fa-user-clock fa-3x text-primary"></i>
                            </div>
                            <h5>账户状态</h5>
                            <span class="badge bg-success">正常</span>
                            <div class="mt-3">
                                <small class="text-muted">
                                    注册时间: <?php echo $currentUser['created_at']; ?>
                                </small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
